package com.chlitina.store.modules.cash.model.recharge;

import java.util.ArrayList;
import java.util.List;

import com.chlitina.store.modules.cash.model.AllCardPayment;
import com.chlitina.store.modules.cash.model.DurationCardPayment;
import com.chlitina.store.modules.cash.model.ProductCardPayment;
import com.chlitina.store.modules.cash.model.TimesCardPayment;

public class RehcargeHost {
	public RehcargeHost() {
	}

	private CardDetail cardDetail;
	private List<Recharge> recharges = new ArrayList<Recharge>();

	public RehcargeHost(Object card, int uuid) {
		this.card = card;
		this.uuid = uuid;
	}

	private int uuid;
	private Object card;

	public int getUuid() {
		return uuid;
	}

	public void setUuid(int uuid) {
		this.uuid = uuid;
	}

	public Object getCard() {
		return card;
	}

	public void setCard(Object card) {
		this.card = card;
	}

	public CardDetail getCardDetail() {
		if (cardDetail == null) {
			cardDetail = CardDetailFactory.createCardDetail(card);
		}
		return cardDetail;
	}

	public List<Recharge> getRecharges() {
		return recharges;
	}

	public void setRecharges(List<Recharge> recharges) {
		this.recharges = recharges;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		if (card instanceof AllCardPayment) {
			AllCardPayment cardPayment = ((AllCardPayment) card);
			sb.append(cardPayment.toString());
		}
		return sb.toString();

	}

	public String getCardName(){
		return  getCardDetail().getName();
	}
	
	public void recharge() {
		if (card instanceof AllCardPayment) {
			AllCardPayment cardPayment = ((AllCardPayment) card);
			for (Recharge recharge : recharges) {
				cardPayment.recharge((CardAllRecharge) recharge);
			}
			System.err.println("Finish Recharges:" + cardPayment.toString());

		} else if (card instanceof ProductCardPayment) {
			ProductCardPayment cardPayment = ((ProductCardPayment) card);
			for (Recharge recharge : recharges) {
				cardPayment.recharge((CardProductRecharge) recharge);
			}
			System.err.println("Finish Recharges:" + cardPayment.toString());
		} else if (card instanceof DurationCardPayment) {
			DurationCardPayment cardPayment = ((DurationCardPayment) card);
			for (Recharge recharge : recharges) {
				cardPayment.recharge((CardDurationRecharge) recharge);
			}
			System.err.println("Finish Recharges:" + cardPayment.toString());
		} else if (card instanceof TimesCardPayment) {
			TimesCardPayment cardPayment = ((TimesCardPayment) card);
			for (Recharge recharge : recharges) {
				cardPayment.recharge((CardTimesRecharge) recharge);
			}
			System.err.println("Finish Recharges:" + cardPayment.toString());
		}
	}
}
